<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const o = { name: "laopi" };
      //   参数一是继承的属性
      const o1 = Object.create(null);
      console.log(o1);

      const o2 = Object.create(o);
      console.log("o2", o2);

      //   参数二
      const o3 = Object.create(null, {
        name: {
          value: "qq",
          writable: false, //是否可写
          enumerable: false, //是否可枚举
          configurable: false, //是否可以删除或者修改配置
        },
        age: {
          value: 22,
        },
      });

      //   新增属性
      Object.defineProperty(o3, "gender", {
        value: "male",
        writable: true,
        enumerable: false,
        configurable: false,
      });

      console.log("o3:", o3);

      //   存取器属性
      const o4 = Object.create(null, {
        firstName: {
          value: "q",
          writable: true,
        },
        lastName: {
          value: "W",
          writable: true,
        },
      });

      Object.defineProperty(o4, "fullname", {
        get() {
          return this.firstName + " " + this.lastName;
        },

        set(value) {
          console.log(value);
          const [firstName, lastName] = value.split(" ");
          this.firstName = firstName;
          this.lastName = lastName;
        },
      });

      console.log("o4", o4);
      //   o4.fullname = "aaa zaaa";
      console.log(o4);

      const o5 = Object.create(null, {
        name: {
          value: "pp",
          writable: true,
        },
        age: {
          value: 11,
          writable: true,
        },
      });

      Object.defineProperty(o5, "description", {
        get() {
          return this.name + " " + this.age;
        },
        set(val) {
          const [age, value] = val.split(" ");

          this.age = age;
          this.name = name;
        },
      });

      console.log("o5", o5);
    </script>
  </body>
</html>
